package com.nuanshui.heatedloan.baseservice.form;

import com.google.common.collect.Lists;
import com.nuanshui.framework.res.ResourceFacade;
import com.nuanshui.framework.springContext.SpringContextUtil;
import com.nuanshui.heatedloan.baseservice.model.WeexVersion;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.List;


public class WeexVersionForm extends WeexVersion{

	private static final long serialVersionUID = 1L;
	private String fileKey;
	private String androidNativeVersionCodeStr;
	private String iosNativeVersionCodeStr;
	
	public String getAndroidNativeVersionCodeStr() {
		if(StringUtils.isEmpty(androidNativeVersionCodeStr)) return null;
		return androidNativeVersionCodeStr;
	}
	public void setAndroidNativeVersionCodeStr(String androidNativeVersionCodeStr) {
		this.androidNativeVersionCodeStr = androidNativeVersionCodeStr;
	}
	public String getIosNativeVersionCodeStr() {
		if(StringUtils.isEmpty(iosNativeVersionCodeStr)) return null;
		return iosNativeVersionCodeStr;
	}
	public void setIosNativeVersionCodeStr(String iosNativeVersionCodeStr) {
		this.iosNativeVersionCodeStr = iosNativeVersionCodeStr;
	}
	public String getFileKey() {
		return fileKey;
	}
	public void setFileKey(String fileKey) {
		this.fileKey = fileKey;
	}
	
	@Override
	public String getPatchUrl(){
		if(StringUtils.isNotEmpty(this.fileKey)){
			ResourceFacade facade = SpringContextUtil.getBean(ResourceFacade.class);
			String url = facade.resolveUrl(this.fileKey);
			if(url.contains("?")){
				int index = url.indexOf("?");
				url = url.substring(0, index);
			}
			return url;
		}
		return super.getPatchUrl();
	}
	
	@Override
	public List<String> getAndroidNativeVersionCode(){
		
		if(StringUtils.isNoneEmpty(this.androidNativeVersionCodeStr)){
			String[] str = this.androidNativeVersionCodeStr.split(",");
			List<String> strList = Lists.newArrayList();
			Collections.addAll(strList, str);
			return strList;
		}
		return super.getAndroidNativeVersionCode();
	}
	
	@Override
	public List<String> getIosNativeVersionCode() {
		if(StringUtils.isNoneEmpty(this.iosNativeVersionCodeStr)){
			String[] str = this.iosNativeVersionCodeStr.split(",");
			List<String> strList = Lists.newArrayList();
			Collections.addAll(strList, str);
			return strList;
		}
		return super.getIosNativeVersionCode();
	}
}
